package com.ruoyi.bysj.controller;

import java.util.List;

import com.ruoyi.bysj.service.ISysGoodsService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bysj.domain.SysGroups;
import com.ruoyi.bysj.service.ISysGroupsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修分组Controller
 * 
 * @author laow
 * @date 2021-10-17
 */
@RestController
@RequestMapping("/bysj/groups")
public class SysGroupsController extends BaseController
{
    @Autowired
    private ISysGroupsService sysGroupsService;

    @Autowired
    private ISysGoodsService sysGoodsService;

    /**
     * 查询维修分组列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:groups:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGroups sysGroups)
    {
        startPage();
        List<SysGroups> list = sysGroupsService.selectSysGroupsList(sysGroups);
        return getDataTable(list);
    }

    /**
     * 导出维修分组列表
     */
    @PreAuthorize("@ss.hasPermi('bysj:groups:export')")
    @Log(title = "维修分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysGroups sysGroups)
    {
        List<SysGroups> list = sysGroupsService.selectSysGroupsList(sysGroups);
        ExcelUtil<SysGroups> util = new ExcelUtil<SysGroups>(SysGroups.class);
        return util.exportExcel(list, "维修分组数据");
    }

    /**
     * 获取维修分组详细信息
     */
    @PreAuthorize("@ss.hasPermi('bysj:groups:query')")
    @GetMapping(value = { "/", "/{groupId}" })
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        AjaxResult ajax = AjaxResult.success();
        ajax.put("goods",sysGoodsService.selectGoodsAll());
        if (StringUtils.isNotNull(groupId))
        {
            ajax.put(AjaxResult.DATA_TAG, sysGroupsService.selectSysGroupsByGroupId(groupId));
        }

        return ajax;
       /* return AjaxResult.success(sysGroupsService.selectSysGroupsByGroupId(groupId));*/
    }

    /**
     * 新增维修分组
     */
    @PreAuthorize("@ss.hasPermi('bysj:groups:add')")
    @Log(title = "维修分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGroups sysGroups)
    {
        return toAjax(sysGroupsService.insertSysGroups(sysGroups));
    }

    /**
     * 修改维修分组
     */
    @PreAuthorize("@ss.hasPermi('bysj:groups:edit')")
    @Log(title = "维修分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGroups sysGroups)
    {
        return toAjax(sysGroupsService.updateSysGroups(sysGroups));
    }

    /**
     * 删除维修分组
     */
    @PreAuthorize("@ss.hasPermi('bysj:groups:remove')")
    @Log(title = "维修分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(sysGroupsService.deleteSysGroupsByGroupIds(groupIds));
    }
}
